package com.tanhua.server.controller;

import com.tanhua.server.service.SoundService;
import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.vo.SoundVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zwy
 */
@RestController
@RequestMapping("peachblossom")
public class SoundController {

    @Autowired
    private SoundService soundService;

    @Autowired
    private TodayBestService todayBestService;

    /**
     * 功能描述: saveSound   保存声音
     *
     * @param soundFile
     * @Return: {@link ResponseEntity< Void>}
     * @throws:
     * @Author: zwy
     * @Date: 2020/12/22 20:41
     */
    @PostMapping
    public ResponseEntity<Void> saveSound(@RequestParam(value = "soundFile", required = false) MultipartFile[] soundFile) {
        try {
            String id = this.soundService.saveSound(soundFile);
            if (StringUtils.isNotEmpty(id)) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 功能描述: receiveSound   接收语音
     *
     * @param
     * @Return: {@link ResponseEntity<com.tanhua.server.vo.SoundVo>}
     * @throws:
     * @Author: zwy
     * @Date: 2020/12/23 9:44
     */
    @GetMapping
    public ResponseEntity<SoundVo> receiveSound() {
        try {
            SoundVo soundVo = this.soundService.receiveSound();
            return ResponseEntity.ok(soundVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 喜欢
     *
     * @param id
     * @return
     */
    @GetMapping("{id}/love")
    public ResponseEntity<Void> likeUser(@PathVariable("id") Long id) {
        try {
            this.todayBestService.likeUser(id);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 不喜欢
     *
     * @param id
     * @return
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> disLikeUser(@PathVariable("id") Long id) {
        try {
            this.todayBestService.disLikeUser(id);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

}
